<template>
	<view>
		<view class="topnav">
			<van-nav-bar title="注册"  left-arrow @click-left="onClickLeft">
			</van-nav-bar>
		</view>
		
		<view class="box">
			<view class="log">
				<view class="title">
					<text>注册</text>
				</view>
				<view class="user">
					<input type="number" placeholder="请输入您的账户(手机号)" v-model="user" maxlength="11" @blur="verifyUser">
					<input type="password" name="pwd" id="" v-model="pwd" placeholder="请输入您的密码" >
					<input type="password" name="pwd" id="" v-model="qrpwd" placeholder="再次输入您的密码" @blur="verifyPwd">
				</view>
				
				<view class="clicklogin">
					<van-button round type="info" color="#085710" @click="regUser" size="large"> 注 册 </van-button>
				</view>
			</view>
			
			<view class="toregister">
				已有账户? <text>登录</text>
			</view>
		</view>
	</view>
</template>

<script>
	import {VerifyInfo,RegIster} from '../../request/api.js'
	export default {
		data() {
			return {
				user:'',
				pwd:'',
				qrpwd:''
			}
		},
		methods: {
			// 验证用户是否存在
			verifyUser(){
				VerifyInfo(this.user,(res)=>{
					if(res.code==201){
						this.$notify(res.msg)
					}
				})
			},
			// 验证两次输入的密码是否一致
			verifyPwd(){
				if(this.pwd != this.qrpwd){
					this.$notify('两次密码不一致')
				}else{
					this.pwd == this.qrpwd
				}
			},
			// 注册用户
				
			regUser(){
				// console.log(this.user,this.pwd);
				// 获取到当前时间将当前时间作为addre
				let addre = new Date().getTime().toString()
				// 将获取到的时间进行截取
				addre = addre.slice(5,-1)
				let oid = addre.slice(4,-1)
				// 将截取后的数据转换为Number类型
				addre = parseInt(addre)
				oid = parseInt(oid)
				RegIster({user:this.user,pwd:this.pwd,addre,oid},(res)=>{
					if(res.code==200){
						this.$notify({type:'success',message:res.msg})
						uni.navigateTo({
							url:'/pages/login/login'
						})
					}
				})
			}
		}
	}
</script>

<style lang="less">
page{
	background-color: #f3f3f3;
}
.topnav{
	border-bottom: 1rpx solid #aaaaaa;
}
	
.box{
	width: 100%;
	height: 89vh;
	box-sizing: border-box;
	padding: 40rpx;
	.log{
		border-radius: 15rpx;
		width: 100%;
		height: 650rpx;
		background-color: white;
		box-sizing: border-box;
		padding: 30rpx 20rpx;
		.title {
			margin: 20rpx 0;
			text-align: center;
			text{
			font-size: 1.8rem;
			}
		}
		.login{
			text-align: center;
			text{
				color: #aaaaaa;
			}
		}
	}
	.user{
		margin: 40rpx 0;
	}
	.user input{
		border: 1rpx solid #085710;
		height: 80rpx;
		margin-bottom: 15rpx;
		text-indent: 1em;
		border-radius: 50rpx;
	}
	// 点击按钮
	.clicklogin{
		margin: 50rpx 0;
		display: flex;
		justify-content: space-around;
	}
	.wj{
		margin: 10rpx 0;
		text-align: right;
		text{
			
		}
	}

// 还没有账号去注册
.toregister{
	margin-top: 600rpx;
	text-align: center;
	color: #9a9a9a;
	text{
		color: #353535;
	}
}
}
body .van-toast{
	background-color: coral;
}
</style>
